/*
 * AppointmentView.java
 */
package khmhappointmentsystem;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class AppointmentView extends FrameView {

    FrmClinic frmClinic = null;
    FrmPatientInformation frmPatientInformation = null;
    FrmNewAppointment frmNewAppointment = null;
    FrmUpdateClinic frmUpdateClinic = null;
    FrmCurrentAppointment frmCurrentAppointment = null;
    FrmPatientHistory frmPatientHistory = null;
    FrmCloseAppointments frmCloseAppointments = null;
    FrmPatientTally frmPatientTally = null;
    FrmUsers frmUsers = null;
    FrmChangePassword frmChangePassword = null;
    FrmUpdateUser frmUpdateUser = null;
    FrmClinicListing frmClinicListing = null;
    FrmTherapy frmTherapy = null;
    FrmProductivityReport frmProductivityReport = null;
    public TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());

    public AppointmentView(SingleFrameApplication app) {
        super(app);

        initComponents();
        Environment.createConnection();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        Environment.setDesktopPane(DesktopPane);
        showLoginScreen();
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = Main.getApplication().getMainFrame();
            aboutBox = new KHMHAppointmentSystemAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        Main.getApplication().show(aboutBox);
    }

    public static void checkPrivileges() {

        //FILE MENU
        fileMenu.setEnabled(UserCheck.canSeeFile());
        fileMenu.setEnabled(UserCheck.canLogout());
        fileMenu.setEnabled(UserCheck.canChangePassword());
        //PATIENT MENU
        PatientMenu.setEnabled(UserCheck.canSeePatient());
        PatientMenu.setEnabled(UserCheck.canRegister());
        PatientMenu.setEnabled(UserCheck.canSeeHistory());
        //APPOINTMENT MENU
        AppointmentMenu.setEnabled(UserCheck.canSeeAppointment());
        AppointmentMenu.setEnabled(UserCheck.canScheduleAppointments());
        AppointmentMenu.setEnabled(UserCheck.canSeeAppointments());
        AppointmentMenu.setEnabled(UserCheck.canClose());
        //CLINICS MENU
        ClinicMenu.setEnabled(UserCheck.canSeeClinics());
        ClinicMenu.setEnabled(UserCheck.canCreateClinics());
        ClinicMenu.setEnabled(UserCheck.canEditClinics());
        //Physiotherapy Menu
        PhysiotherapyMenu.setEnabled(UserCheck.canSeeTherapy());
        PhysiotherapyMenu.setEnabled(UserCheck.canSeeTherapyReport());
        //REPORTS MENU
        ReportMenu.setEnabled(UserCheck.canSeeReports());
        ReportMenu.setEnabled(UserCheck.canSeeTally());
        ReportMenu.setEnabled(UserCheck.canSeeClinicListing());
        //PERMISSIONS REPORTS
        PermissionsMenu.setEnabled(UserCheck.canSeePermissions());
        PermissionsMenu.setEnabled(UserCheck.canCreateNewUser());
        PermissionsMenu.setEnabled(UserCheck.canUpdateUser());
        //HELP REPORTS
        HelpMenu.setEnabled(UserCheck.canSeeHelp());
        HelpMenu.setEnabled(UserCheck.canSeeAbout());
    }

    protected boolean isLoaded(String FormTitle) {
        JInternalFrame Form[] = DesktopPane.getAllFrames();
        for (int i = 0; i < Form.length; i++) {
            if (Form[i].getTitle().equalsIgnoreCase(FormTitle)) {
                Form[i].show();
                try {
                    Form[i].setIcon(false);
                    Form[i].setSelected(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return true;
            }
        }

        return false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        DesktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        mnuChangePassword = new javax.swing.JMenuItem();
        PatientMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        AppointmentMenu = new javax.swing.JMenu();
        mnuSchedule = new javax.swing.JMenuItem();
        mnuCurrent = new javax.swing.JMenuItem();
        mnureschedule = new javax.swing.JMenuItem();
        ClinicMenu = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        PhysiotherapyMenu = new javax.swing.JMenu();
        mnuappointment = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        ReportMenu = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        PermissionsMenu = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        HelpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setFocusCycleRoot(true);
        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(AppointmentView.class);
        DesktopPane.setBackground(resourceMap.getColor("DesktopPane.background")); // NOI18N
        DesktopPane.setName("DesktopPane"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(DesktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 717, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(DesktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(AppointmentView.class, this);
        fileMenu.setAction(actionMap.get("Logout")); // NOI18N
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setIcon(resourceMap.getIcon("exitMenuItem.icon")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        mnuChangePassword.setAction(actionMap.get("ChangePassword")); // NOI18N
        mnuChangePassword.setText(resourceMap.getString("mnuChangePassword.text")); // NOI18N
        mnuChangePassword.setName("mnuChangePassword"); // NOI18N
        fileMenu.add(mnuChangePassword);

        menuBar.add(fileMenu);

        PatientMenu.setAction(actionMap.get("PatientHistory")); // NOI18N
        PatientMenu.setText(resourceMap.getString("PatientMenu.text")); // NOI18N
        PatientMenu.setName("PatientMenu"); // NOI18N

        jMenuItem1.setAction(actionMap.get("registration")); // NOI18N
        jMenuItem1.setIcon(resourceMap.getIcon("jMenuItem1.icon")); // NOI18N
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        PatientMenu.add(jMenuItem1);

        jMenuItem2.setAction(actionMap.get("PatientHistory")); // NOI18N
        jMenuItem2.setIcon(resourceMap.getIcon("jMenuItem2.icon")); // NOI18N
        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        PatientMenu.add(jMenuItem2);

        menuBar.add(PatientMenu);

        AppointmentMenu.setAction(actionMap.get("CurrentAppointments")); // NOI18N
        AppointmentMenu.setText(resourceMap.getString("AppointmentMenu.text")); // NOI18N
        AppointmentMenu.setName("AppointmentMenu"); // NOI18N

        mnuSchedule.setAction(actionMap.get("Schedule")); // NOI18N
        mnuSchedule.setIcon(resourceMap.getIcon("mnuSchedule.icon")); // NOI18N
        mnuSchedule.setText(resourceMap.getString("mnuSchedule.text")); // NOI18N
        mnuSchedule.setName("mnuSchedule"); // NOI18N
        AppointmentMenu.add(mnuSchedule);

        mnuCurrent.setAction(actionMap.get("CurrentAppointments")); // NOI18N
        mnuCurrent.setIcon(resourceMap.getIcon("mnuCurrent.icon")); // NOI18N
        mnuCurrent.setText(resourceMap.getString("mnuCurrent.text")); // NOI18N
        mnuCurrent.setName("mnuCurrent"); // NOI18N
        AppointmentMenu.add(mnuCurrent);

        mnureschedule.setAction(actionMap.get("CloseAppointment")); // NOI18N
        mnureschedule.setIcon(resourceMap.getIcon("mnureschedule.icon")); // NOI18N
        mnureschedule.setText(resourceMap.getString("mnureschedule.text")); // NOI18N
        mnureschedule.setName("mnureschedule"); // NOI18N
        AppointmentMenu.add(mnureschedule);

        menuBar.add(AppointmentMenu);

        ClinicMenu.setText(resourceMap.getString("ClinicMenu.text")); // NOI18N
        ClinicMenu.setName("ClinicMenu"); // NOI18N

        jMenuItem5.setAction(actionMap.get("createClinic")); // NOI18N
        jMenuItem5.setIcon(resourceMap.getIcon("jMenuItem5.icon")); // NOI18N
        jMenuItem5.setText(resourceMap.getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.setName("jMenuItem5"); // NOI18N
        ClinicMenu.add(jMenuItem5);

        jMenuItem3.setAction(actionMap.get("UpdateClinic")); // NOI18N
        jMenuItem3.setIcon(resourceMap.getIcon("jMenuItem3.icon")); // NOI18N
        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        ClinicMenu.add(jMenuItem3);

        menuBar.add(ClinicMenu);

        PhysiotherapyMenu.setText(resourceMap.getString("PhysiotherapyMenu.text")); // NOI18N
        PhysiotherapyMenu.setName("PhysiotherapyMenu"); // NOI18N

        mnuappointment.setAction(actionMap.get("Physiotherapy")); // NOI18N
        mnuappointment.setIcon(resourceMap.getIcon("mnuappointment.icon")); // NOI18N
        mnuappointment.setText(resourceMap.getString("mnuappointment.text")); // NOI18N
        mnuappointment.setName("mnuappointment"); // NOI18N
        PhysiotherapyMenu.add(mnuappointment);

        jMenuItem7.setAction(actionMap.get("PhysiotherapyReport")); // NOI18N
        jMenuItem7.setText(resourceMap.getString("jMenuItem7.text")); // NOI18N
        jMenuItem7.setName("jMenuItem7"); // NOI18N
        PhysiotherapyMenu.add(jMenuItem7);

        menuBar.add(PhysiotherapyMenu);

        ReportMenu.setText(resourceMap.getString("ReportMenu.text")); // NOI18N
        ReportMenu.setName("ReportMenu"); // NOI18N

        jMenuItem4.setAction(actionMap.get("TallyCheckin")); // NOI18N
        jMenuItem4.setIcon(resourceMap.getIcon("jMenuItem4.icon")); // NOI18N
        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        ReportMenu.add(jMenuItem4);

        jMenuItem9.setAction(actionMap.get("ClinicListing")); // NOI18N
        jMenuItem9.setText(resourceMap.getString("jMenuItem9.text")); // NOI18N
        jMenuItem9.setName("jMenuItem9"); // NOI18N
        ReportMenu.add(jMenuItem9);

        menuBar.add(ReportMenu);

        PermissionsMenu.setText(resourceMap.getString("PermissionsMenu.text")); // NOI18N
        PermissionsMenu.setName("PermissionsMenu"); // NOI18N

        jMenuItem6.setAction(actionMap.get("NewUser")); // NOI18N
        jMenuItem6.setIcon(resourceMap.getIcon("jMenuItem6.icon")); // NOI18N
        jMenuItem6.setText(resourceMap.getString("jMenuItem6.text")); // NOI18N
        jMenuItem6.setName("jMenuItem6"); // NOI18N
        PermissionsMenu.add(jMenuItem6);

        jMenuItem8.setAction(actionMap.get("UpdateUser")); // NOI18N
        jMenuItem8.setIcon(resourceMap.getIcon("jMenuItem8.icon")); // NOI18N
        jMenuItem8.setText(resourceMap.getString("jMenuItem8.text")); // NOI18N
        jMenuItem8.setName("jMenuItem8"); // NOI18N
        PermissionsMenu.add(jMenuItem8);

        menuBar.add(PermissionsMenu);

        HelpMenu.setText(resourceMap.getString("HelpMenu.text")); // NOI18N
        HelpMenu.setName("HelpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setIcon(resourceMap.getIcon("aboutMenuItem.icon")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        HelpMenu.add(aboutMenuItem);

        menuBar.add(HelpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 717, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 547, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void registration() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Register Patient");
        if (AlreadyLoaded == false) {
            frmPatientInformation = new FrmPatientInformation();
            DesktopPane.add(frmPatientInformation);
            //frmRegistration = new FrmRegistration(dbConn_appointment);
            //DesktopPane.add(frmRegistration);

            //Load the Form
            frmPatientInformation.setVisible(true);
            frmPatientInformation.show();
            try {
                frmPatientInformation.setIcon(false);
                frmPatientInformation.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmPatientInformation.setIcon(false);
                frmPatientInformation.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * Shows the Login Screen.
     */
    private void showLoginScreen() {
        FrmLogin frmLogin = new FrmLogin(this.getFrame(), true);
        frmLogin.setLocationRelativeTo(this.getFrame());
        frmLogin.setVisible(true);
    }

    @Action
    public void close() {
        //Close Database Connection and Close the Application
        try {
            Environment.getDbConn().close();
        } catch (SQLException ex) {
        }

        System.exit(0);
    }

    @Action
    public void createClinic() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Create New Clinic");
        if (AlreadyLoaded == false) {
            frmClinic = new FrmClinic();
            DesktopPane.add(frmClinic);

            //Load the Form
            frmClinic.setVisible(true);
            frmClinic.show();
            try {
                frmClinic.setIcon(false);
                frmClinic.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmClinic.setIcon(false);
                frmClinic.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void Schedule() {
        boolean AlreadyLoaded = isLoaded("Schedule Appointment");
        if (AlreadyLoaded == false) {
            frmNewAppointment = new FrmNewAppointment();
            DesktopPane.add(frmNewAppointment);

            //Load the Form
            frmNewAppointment.setVisible(true);
            frmNewAppointment.show();
            try {
                frmNewAppointment.setIcon(false);
                frmNewAppointment.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmNewAppointment.setIcon(false);
                frmNewAppointment.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    @Action
    public void UpdateClinic() throws Exception {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Update Clinic");
        if (AlreadyLoaded == false) {
            frmUpdateClinic = new FrmUpdateClinic();
            DesktopPane.add(frmUpdateClinic);

            //Load the Form
            frmUpdateClinic.setVisible(true);
            frmUpdateClinic.show();
            try {
                frmUpdateClinic.setIcon(false);
                frmUpdateClinic.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmUpdateClinic.setIcon(false);
                frmUpdateClinic.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void CurrentAppointments() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Current Appointment");
        if (AlreadyLoaded == false) {
            frmCurrentAppointment = new FrmCurrentAppointment();
            DesktopPane.add(frmCurrentAppointment);

            //Load the Form
            frmCurrentAppointment.setVisible(true);
            frmCurrentAppointment.show();
            try {
                frmCurrentAppointment.setIcon(false);
                frmCurrentAppointment.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmCurrentAppointment.setIcon(false);
                frmCurrentAppointment.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void PatientHistory() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Patient History");
        if (AlreadyLoaded == false) {
            frmPatientHistory = new FrmPatientHistory();
            DesktopPane.add(frmPatientHistory);

            //Load the Form
            frmPatientHistory.setVisible(true);
            frmPatientHistory.show();
            try {
                frmPatientHistory.setIcon(false);
                frmPatientHistory.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmPatientHistory.setIcon(false);
                frmPatientHistory.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void CloseAppointment() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Close Appointment Period");
        if (AlreadyLoaded == false) {
            frmCloseAppointments = new FrmCloseAppointments();
            DesktopPane.add(frmCloseAppointments);

            //Load the Form
            frmCloseAppointments.setVisible(true);
            frmCloseAppointments.show();
            try {
                frmCloseAppointments.setIcon(false);
                frmCloseAppointments.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmCloseAppointments.setIcon(false);
                frmCloseAppointments.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void TallyCheckin() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Specialist Clinic Tally Check In");
        if (AlreadyLoaded == false) {
            frmPatientTally = new FrmPatientTally();
            DesktopPane.add(frmPatientTally);

            //Load the Form
            frmPatientTally.setVisible(true);
            frmPatientTally.show();
            try {
                frmPatientTally.setIcon(false);
                frmPatientTally.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmPatientTally.setIcon(false);
                frmPatientTally.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void NewUser() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Create New User.");
        if (AlreadyLoaded == false) {
            frmUsers = new FrmUsers();
            DesktopPane.add(frmUsers);

            //Load the Form
            frmUsers.setVisible(true);
            frmUsers.show();
            try {
                frmUsers.setIcon(false);
                frmUsers.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmUsers.setIcon(false);
                frmUsers.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void Logout() {
        String message = "Are you sure you want to logout?";
        int response = Utilities.showConfirmDialog(getFrame(), message);
        if (response == JOptionPane.YES_OPTION) {
            for (JInternalFrame frame : Environment.getDesktopPane().getAllFrames()) {
                frame.dispose();
            }
            message = "The user successfully logged Off.";
            iLogger.logMessage(message, "Log Off", "User");
            showLoginScreen();
            //checkPrivileges();
        }

    }

    @Action
    public void ChangePassword() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Change Password.");
        if (AlreadyLoaded == false) {
            frmChangePassword = new FrmChangePassword();
            DesktopPane.add(frmChangePassword);

            //Load the Form
            frmChangePassword.setVisible(true);
            frmChangePassword.show();
            try {
                frmChangePassword.setIcon(false);
                frmChangePassword.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmChangePassword.setIcon(false);
                frmChangePassword.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void UpdateUser() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Update User Information.");
        if (AlreadyLoaded == false) {
            frmUpdateUser = new FrmUpdateUser();
            DesktopPane.add(frmUpdateUser);

            //Load the Form
            frmUpdateUser.setVisible(true);
            frmUpdateUser.show();
            try {
                frmUpdateUser.setIcon(false);
                frmUpdateUser.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmUpdateUser.setIcon(false);
                frmUpdateUser.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void ClinicListing() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Specialist Clinic Listings");
        if (AlreadyLoaded == false) {
            frmClinicListing = new FrmClinicListing();
            DesktopPane.add(frmClinicListing);

            //Load the Form
            frmClinicListing.setVisible(true);
            frmClinicListing.show();
            try {
                frmClinicListing.setIcon(false);
                frmClinicListing.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmClinicListing.setIcon(false);
                frmClinicListing.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void Physiotherapy() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Physiotherapy Department");
        if (AlreadyLoaded == false) {
            frmTherapy = new FrmTherapy();
            DesktopPane.add(frmTherapy);

            //Load the Form
            frmTherapy.setVisible(true);
            frmTherapy.show();
            try {
                frmTherapy.setIcon(false);
                frmTherapy.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmTherapy.setIcon(false);
                frmTherapy.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Action
    public void PhysiotherapyReport() {
        //Verify if the form is already loaded
        boolean AlreadyLoaded = isLoaded("Physiotherapy Productivity Report");
        if (AlreadyLoaded == false) {
            frmProductivityReport = new FrmProductivityReport();
            DesktopPane.add(frmProductivityReport);

            //Load the Form
            frmProductivityReport.setVisible(true);
            frmProductivityReport.show();
            try {
                frmProductivityReport.setIcon(false);
                frmProductivityReport.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //End load Form
        } else {
            try {
                frmProductivityReport.setIcon(false);
                frmProductivityReport.setSelected(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JMenu AppointmentMenu;
    private static javax.swing.JMenu ClinicMenu;
    private javax.swing.JDesktopPane DesktopPane;
    private static javax.swing.JMenu HelpMenu;
    private static javax.swing.JMenu PatientMenu;
    private static javax.swing.JMenu PermissionsMenu;
    private static javax.swing.JMenu PhysiotherapyMenu;
    private static javax.swing.JMenu ReportMenu;
    private static javax.swing.JMenu fileMenu;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private static javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem mnuChangePassword;
    private javax.swing.JMenuItem mnuCurrent;
    private javax.swing.JMenuItem mnuSchedule;
    private javax.swing.JMenuItem mnuappointment;
    private javax.swing.JMenuItem mnureschedule;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
